/****************************************************************************
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) Microsoft Open Technologies, Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/


#ifndef MAINGAMESCENE_H
#define MAINGAMESCENE_H

#include "cocos2d.h"
//#include "game.h"
#include "AppDelegate.h"
#include "GameLayer.h"

USING_NS_CC;
using namespace std;
using namespace cocos2d;

///@brief Scene show the game ui.
class MainGameScene : public MyScene
{
public:
    MainGameScene();
    virtual ~MainGameScene();

    ///@brief calculate the score
    ///@param t time in second.
    ///@param mov the player move step.
    ///@param dif difficulty or the size of the game chess board.
    ///@param mix disfusion when the game data initiated.
    int calcScore(int t,int mov,int dif, int mix);

    //void setUseSaved(bool use);

    virtual bool init(); ///<Initiation when the scene is created.

    virtual void onEnter(); ///<When the scene begins to show.

    void menuBackCallback(); ///<Callback when press "Back"

    CREATE_FUNC(MainGameScene);


    friend class GameLayer;
    friend class GameWinLayer;

    virtual void onExit(); ///<Save data before exit.

    static bool useSaved; ///<Load game from file or create a new one.

protected:
    void gameStepIncrease(); ///<Callback when the player move
    void gameTimerCallback(float t); ///<Callback when the timer spends 1 second.

    void showWin(); ///<Show wining

    void saveGameStat(); ///<Save the current game data.
    void loadGameStat(); ///<load the game data last played.

private:

    GameModel* _model; ///<The model of game.

    CCLabelBMFont* ltime; ///Label to show time
    CCLabelBMFont* lstep; ///Label to show move step.

    int useStep; ///<
    int useTime; ///<
    int diff; ///<game difficulty
    int score; ///<
    int picId; ///<the game picture id.

};

///@brief To show the winning scene.
class GameWinLayer:public CCLayer
{
public:
    ///@brief Set the basic data.
    void setGameResult(int score,int move,int difficulty);

    virtual bool init();
    virtual void onEnter();

    void IncreaseScore(float dt); ///<Callback when the score increased.

    CREATE_FUNC(GameWinLayer);

private:
    int score;
    int difficulty;
    int move;

    int tmps, ///<the count when score increasing
        delta;

    CCLabelBMFont* ldif; ///<Label to show difficulty
    CCLabelBMFont* lmove; ///<Label to show move step.
    CCLabelBMFont* lscore; ///<Label to show score.

};


#endif // MAINGAMESCENE_H
